﻿using System;
using System.Linq;
using System.Web.UI.WebControls;

namespace BEELab.MasterPage
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            Page.ViewStateUserKey = Session["ViewStateUserKey"].ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserEmail"] == null || Session["UserEmail"].ToString().Length == 0)
            {
                Response.Redirect("Default.aspx");
            }
            else
            {
                lblUserDetail.Text = Session["UserEmail"].ToString();
            }
        }

        // highlights the current menu link in the navbar
        private void HighlightCurrentMenuItem()
        {
            foreach (var link in phMenu.Controls.OfType<HyperLink>())
            {
                var nav = link.NavigateUrl.Trim(new char[] { ' ', '/', '~' });
                if (Request.Url.AbsolutePath.Contains(nav.Substring(0, nav.IndexOf('/') < 0 ? nav.Length - 1 : nav.IndexOf('/'))))
                {
                    link.CssClass = "active";
                    break;
                }
            }
        }

        protected void lnkSignOut_Click(object sender, EventArgs e)
        {
            Session["UserID"] = null;
            Session["UserEmail"] = null;
            Session["Admin"] = null;
            Response.Redirect("Default.aspx");
        }
    }
}